var isValid = function (s) {
  const pairs = new Map([
    [")", "("],
    ["]", "["],
    ["}", "{"],
  ]);
  const stk = [];
  for (let ch of s) {
    //!关键一步:检测数组最后面如果都出现闭括号了,那闭括号前一个必须是对应的开括号
    if (pairs.has(ch)) {
      if (!stk.length || stk[stk.length - 1] !== pairs.get(ch)) {
        return false;
      }
      stk.pop();
    }
    //只有左括号才加
    else {
      stk.push(ch);
    }
  }
  return !stk.length;
};
